home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / mflzt.exe / TC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-30  |  1.8 KB  |  73 lines

  1. /*
  2. **                TEXT COMPARE UTILITY
  3. **
  4. **   Copyright 1988-89, S.E. Margison
  5. **
  6. **   This short utility compares two text files and shows
  7. **   any line differences.
  8. **
  9. **   As distributed, this program requires (for compilation):
  10. **     "Steve's Turbo-C Library" version 1.41 or later
  11. **   which may be obtained without registration from many Bulletin
  12. **   Board Systems including:
  13. **      Compuserve IBMSW
  14. **      GEnie
  15. **   and software library houses including:
  16. **      Public (Software) Library (Houston, TX.)
  17. **
  18. **   or by registration:
  19. **      $25 for Docs, C, S, M, L, H libraries, and complete library source
  20. **              in C and Assembler
  21. **     Steven E. Margison
  22. **     124 Sixth Street
  23. **     Downers Grove, IL, 60515
  24. **
  25. **
  26. */
  27.  
  28. #include <stdio.h>
  29. #include <mflstrng.h>
  30.  
  31. #define MAXLINE 192
  32.  
  33. FILE *fp1, *fp2;
  34. char buf1[MAXLINE], buf2[MAXLINE];
  35.  
  36. main(argc, argv)
  37. int argc;
  38. char *argv[];
  39. {
  40.    int lc, end1, end2;
  41.    lc = 0;
  42.    end1 = end2 = FALSE;
  43.  
  44.    if(argc != 3) error("usage: TC file1 file2");
  45.  
  46.    if((fp1 = fopen(argv[1], "r")) == NULL) cant(argv[1]);
  47.  
  48.    if((fp2 = fopen(argv[2], "r")) == NULL) {
  49.       fclose(fp1);
  50.       cant(argv[2]);
  51.       }
  52.  
  53.    for EVER {
  54.       ++lc;
  55.       if(fgets(buf1, MAXLINE, fp1) == NULL) end1 = TRUE;
  56.       if(fgets(buf2, MAXLINE, fp2) == NULL) end2 = TRUE;
  57.       if(end1 || end2) break;
  58.  
  59.       if(strcmp(buf1, buf2)) {
  60.          printf("Line %d in %s\n", lc, argv[1]);
  61.          printf("%s", buf1);
  62.          printf("Line %d in %s\n", lc, argv[2]);
  63.          printf("%s", buf2);
  64.          }
  65.       }
  66.    if(end1 && !end2)
  67.       printf("EOF on %s occured first\n", argv[1]);
  68.    if(end2 && !end1)
  69.       printf("EOF on %s occured first\n", argv[2]);
  70.    fclose(fp1);
  71.    fclose(fp2);
  72.    }
  73.